package dontCare.gwtester.client.puzzlers;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import dontCare.gwtester.client.tool.SourceUrl;
import dontCare.gwtester.client.tool.UnitWidget;

public class Album3 extends UnitWidget{
	private static Album3UiBinder uiBinder = GWT.create(Album3UiBinder.class);
	interface Album3UiBinder extends UiBinder<Widget, Album3> {}

	//Last Laugh
	@UiField Label stringHa;
	@UiField Label charHa;
	
	//ABC
	@UiField Label charArray;
	@UiField Label valueOfCharArray;
	
	//Escape Rout
	@UiField Label escape;
	
	@UiField Label ain;
	
	public Album3() {
		initWidget(uiBinder.createAndBindUi(this));
		lastLaugh();
		abc();
		escape.setText("" + ("a\u0022.length() + \u0022b".length()) );
		noPainNoGain();
	}

	private void lastLaugh() {
		stringHa.setText(""+("H"+"a"));
		charHa.setText(""+('H'+'a'));
	}

	private void abc() {
		String letters = "ABC";
		char[] numbers = {'1', '2', '3'};
		charArray.setText(letters + " easy as " + numbers);
		valueOfCharArray.setText(letters + " easy as " + String.valueOf(numbers));
	}

	private void noPainNoGain() {
		StringBuffer word = null;
		switch(new Random().nextInt(2)){
		case 1: word = new StringBuffer('P');
		case 2: word = new StringBuffer('G');
		default: word = new StringBuffer('M');
		}
		word.append('a');
		word.append('i');
		word.append('n');
		ain.setText(word.toString());
	}

	@Override
	public List<String> getSourceUrl() {
		ArrayList<String> result = new ArrayList<String>();
		result.add(SourceUrl.genJava(Album3.class));
		result.add(SourceUrl.genUiXml(Album3.class));
		return result;
	}

	@Override
	public HTML getDescription() {
		return new HTML("《Java Puzzlers》 Chapter 3 puzzler 集合");
	}

	@Override
	public String getName() {
		return "CH.3 Album";
	}
}